package com.woniu.microassetserver.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.microassetserver.mapper.DomaintypeMapper;
import com.woniu.microassetserver.service.DomaintypeService;
import com.woniu.microcommonsserver.entity.AssetsParameterEntity;
import com.woniu.microcommonsserver.entity.DomaintypeEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


@Transactional(readOnly = true)
@Service
public class DomaintypeServiceImpl implements DomaintypeService {

    @Resource
    private DomaintypeMapper domaintypeMapper;

    @Override
    public PageInfo<DomaintypeEntity> findAllByParams(int pageNum, int pageSize, DomaintypeEntity domaintypeEntity) {

        return PageHelper.startPage(pageNum,pageSize).
                doSelectPageInfo(()->domaintypeMapper.findAllByParams(domaintypeEntity));
    }

    @Override
    public List<DomaintypeEntity> findAll() {
        return domaintypeMapper.findAll();
    }

    @Override
    public List<AssetsParameterEntity> findAssetById(Long id){
        return domaintypeMapper.findAssetById(id);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int saveDomaintype(DomaintypeEntity domaintypeEntity) {
        return domaintypeMapper.saveDomaintype(domaintypeEntity);
    }

    @Override
    public DomaintypeEntity getOneById(Long id) {
        return domaintypeMapper.getOneById(id);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updateDomaintype(DomaintypeEntity domaintypeEntity) {
        return domaintypeMapper.updateDomaintype(domaintypeEntity);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int deleteDomaintype(Long id) {
        return domaintypeMapper.deleteDomaintype(id);
    }
}